package com.ljd.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljd.entity.EduCourse;
import com.ljd.entity.EduTeacher;
import com.ljd.entity.page.PageResponse;
import com.ljd.service.EduCourseService;
import com.ljd.service.EduTeacherService;
import com.ljd.util.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin
@RequestMapping("eduservice/teacherFront")
@Api(description = "前台讲师")
public class TeacherFrontController {
    @Autowired
    EduTeacherService teacherService;
    @Autowired
    EduCourseService courseService;
    @GetMapping("/getTeachers/{currentPage}/{pageSize}")
    public R getTeachers(@PathVariable Long currentPage,@PathVariable Long pageSize){
        PageResponse<EduTeacher> response = teacherService.getTeachers(currentPage,pageSize);
        return R.ok().data("response",response);
    }
    @GetMapping("getTeacherDetail/{teacherId}")
    public R getTeacherDetail(@PathVariable String teacherId){
        // 查询老师基本信息
        EduTeacher teacher = teacherService.getById(teacherId);
        // 查询老师课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId)
                .orderByDesc("id")
                .last("limit 4");
        List<EduCourse> courses = courseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courses",courses);
    }

}
